package com.example.demo.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author vaintale
 * @date 2025/6/28
 */
public class DRLCall {
    public static void main(String[] args) throws IOException, InterruptedException {
        String pythonExe = "/home/vaintale/miniconda3/envs/DGM/bin/python3"; // 或python3，视你的环境而定
        String scriptPath = "/home/vaintale/projecs/java-code/demo/src/main/resources/scripts/DRL.py";
        String networkPath = "/home/vaintale/projecs/java-code/demo/src/main/resources/data/graph/graph.gml";
        String targetConstraintPath = "/home/vaintale/projecs/java-code/demo/src/main/resources/data/graph/output.csv";
        String attackTargetPath = "/home/vaintale/projecs/java-code/demo/src/main/resources/data/graph/DRL.csv";
        String oscillationTime = "100";

        ProcessBuilder pb = new ProcessBuilder(
                pythonExe, scriptPath,
                networkPath,
                targetConstraintPath,
                attackTargetPath,
                oscillationTime,
                "DRL"
        );

        pb.redirectErrorStream(true);
        Process process = pb.start();
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
        int exitCode = process.waitFor();
        System.out.println("Python exit code: " + exitCode);
    }
}
